package com.yu8home.opcua.test;

import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
import org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaSubscription;
import org.eclipse.milo.opcua.sdk.client.subscriptions.OpcUaSubscriptionManager;
import org.eclipse.milo.opcua.stack.core.UaException;
import org.eclipse.milo.opcua.stack.core.types.builtin.DateTime;
import org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode;

public class MySubscriptionListener implements OpcUaSubscriptionManager.SubscriptionListener {
    private OpcUaClient opcUaClient;

    public MySubscriptionListener(OpcUaClient opcUaClient) {
        this.opcUaClient = opcUaClient;
    }

    @Override
    public void onKeepAlive(UaSubscription subscription, DateTime publishTime) {
        System.out.println("onKeepAlive");
    }

    @Override
    public void onStatusChanged(UaSubscription subscription, StatusCode status) {
        System.out.println("onStatusChanged");
    }

    @Override
    public void onPublishFailure(UaException exception) {
        System.out.println("onPublishFailure");
    }

    @Override
    public void onNotificationDataLost(UaSubscription subscription) {
        System.out.println("onNotificationDataLost");
    }

    @Override
    public void onSubscriptionTransferFailed(UaSubscription uaSubscription, StatusCode statusCode) {
        System.out.println("重连时，尝试恢复之前的订阅失败的，需要重新订阅");
        try {
            BatchSub.createSubscribe();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
